package com.zhongkun.datahome.service.domain;

import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zhongkun.datahome.service.processor.dto.HouseMaterialDto;
import com.zhongkun.datahome.service.req.cmd.house.CustomerHouseCmd;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * 客户房产对象 customer_house
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Data
public class CustomerHouse extends BaseEntity {
    @ApiModelProperty("所属家庭id")
    private Long familyId;

    @ApiModelProperty("楼栋号")
    private String buildingNum;

    @ApiModelProperty("房号")
    private String roomNum;

    @ApiModelProperty("房产面积")
    private BigDecimal roomArea;

    @ApiModelProperty("户型名称")
    private String houseName;

    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty("购房时间")
    private Date houseBuyDate;

    @ApiModelProperty("签约状态，0否，1是")
    private Integer signStatus;

    @ApiModelProperty("来源")
    private String source;

    @ApiModelProperty("装修风格")
    private String decoratorStyle;

    @ApiModelProperty("业主小程序是否展示清单，0否，1是")
    private Integer listShowFlag;

    @ApiModelProperty("业主小程序是否展示规格型号，0否，1是")
    private Integer specificationShowFlag;

    @ApiModelProperty("施工计划在小程序中是否展示，0否，1是")
    private Integer buildPlanShowFlag;

    @ApiModelProperty("所属项目")
    private Long projectId;

    @ApiModelProperty("小程序")
    private String miniProgramImg;

    public static CustomerHouse of(CustomerHouseCmd cmd) {
        CustomerHouse customerHouse = new CustomerHouse();
        customerHouse.update(cmd);
        customerHouse.setProjectId(cmd.getProjectId());

        return customerHouse;
    }

    public void update(CustomerHouseCmd cmd) {
        this.setBuildingNum(cmd.getBuildingNum());
        this.setRoomNum(cmd.getRoomNum());
        this.setHouseName(cmd.getHouseName());
        this.setSignStatus(cmd.getSignStatus());
        this.setHouseBuyDate(cmd.getHouseBuyDate());
        this.setRoomArea(cmd.getRoomArea());
        this.setDecoratorStyle(cmd.getDecoratorStyle());
        this.setListShowFlag(cmd.getListShowFlag());
        this.setSpecificationShowFlag(cmd.getSpecificationShowFlag());
    }

    public static CustomerHouse of(HouseMaterialDto houseMaterialDto) {
        CustomerHouse customerHouse = new CustomerHouse();
        customerHouse.setBuildingNum(houseMaterialDto.getBuildingNum());
        customerHouse.setRoomNum(houseMaterialDto.getRoomNum());
        customerHouse.setHouseName(houseMaterialDto.getHouseName());
        customerHouse.setDecoratorStyle(houseMaterialDto.getDecoratorStyle());
        customerHouse.setSignStatus(StringUtils.equals(houseMaterialDto.getSignStatus(), "已签约") ? 1 : 0);

        return customerHouse;
    }

    public String getHouseKey() {
        return MessageFormat.format("{0}-{1}", this.getBuildingNum(), this.getRoomNum());
    }
}
